package com.claimSettlement.controller;

import com.claimSettlement.pojo.Policyholders;
import com.claimSettlement.service.PolicyholdersService;
import com.claimSettlement.service.impl.PolicyholdersServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 投保人信息控制层
 * 曹文韬 -- 2021-05-19
 */
@RestController
@RequestMapping("/policyholders")
public class PolicyholdersController {
    @Resource
    private PolicyholdersService policyholdersService;

    @RequestMapping("/getPolicyholdersAll")
    public PageInfo<Policyholders> getPolicyholdersAll(int page){
        PageHelper.startPage(page,4);
        List<Policyholders> list = policyholdersService.getPolicyholdersAll();
        PageInfo<Policyholders> pageInfo = new PageInfo<Policyholders>(list);
        //一共pageInfo.pages页 --当前页是pageInfo.pageNum  -- 共有pageInfo.total 条数据
        return pageInfo;
    }

    @RequestMapping("/selectPolicyholdersByNameOrCredenId")
    public PageInfo<Policyholders> selectPolicyholdersByNameOrCredenId(String name,String credenId,int page){
        PageHelper.startPage(page,4);
        List<Policyholders> list = policyholdersService.selectPolicyholdersByNameOrCredenId(name, credenId);
        PageInfo<Policyholders> pageInfo = new PageInfo<Policyholders>(list,4);
        return pageInfo;
    }

    @RequestMapping("/getPolicyholdersById")
    public Policyholders getPolicyholdersById(int policyholdersId){
        return policyholdersService.getPolicyholdersById(policyholdersId);
    }

    @RequestMapping(value = "/insPolicyholders", method = RequestMethod.POST,produces = "text/html;charset=UTF-8")
    public String insPolicyholders(@RequestBody Policyholders policyholders){
        return policyholdersService.insPolicyholders(policyholders) > 0 ? "成功":"失败";
    }

    @RequestMapping(value = "/updPolicyholders", method = RequestMethod.POST,produces = "text/html;charset=UTF-8")
    public String updPolicyholders(@RequestBody Policyholders policyholders){
        return policyholdersService.updPolicyholders(policyholders) > 0 ? "成功":"失败";
    }

    @RequestMapping(value = "/delPolicyholders",produces = "text/html;charset=UTF-8")
    public String delPolicyholders(int policyholdersId){
        return policyholdersService.delPolicyholders(policyholdersId) > 0 ? "成功":"失败";
    }
    @RequestMapping("/getPolicyholdersAll2")
    public List<Policyholders> getPolicyholdersAll2(){
        List<Policyholders> list = policyholdersService.getPolicyholdersAll();
        return list;
    }

    @RequestMapping("/getPolicyholdersNameAndId")
    public List<Policyholders> getPolicyholdersNameAndId(){
        return policyholdersService.getPolicyholdersNameAndId();
    }
}
